package com.yiji.fintech.musfinance.test;

import com.yiji.fintech.musfinance.common.annotation.ListenerAnnotation;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.util.Set;

/**
 * Created by ouwen@yiji.com} on 2017/9/14.
 */
public class ScanListener {
    public static void main(String[] args){
        String scanBasePath = "com.yiji.fintech.musfinance";
        ClassPathScanningCandidateComponentProvider provider =
                new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AnnotationTypeFilter(ListenerAnnotation.class));
        Set<BeanDefinition> components = provider.findCandidateComponents(scanBasePath);
        for (BeanDefinition component : components) {
            try {
                Class lister = Class.forName(component.getBeanClassName());
                ListenerAnnotation annotation = (ListenerAnnotation)lister.getAnnotation(ListenerAnnotation.class);
                if(annotation != null){
                    String value = annotation.value();
                    System.out.print(value);
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}
